<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件练习案例</title>
</head>
<body>
    <img src="image/on.gif" alt="#" onclick="alert('关灯')">
    <img src="image/off.gif" alt="#" onclick="fun1()">
    <img src="image/off.gif" alt="#" onclick=fun2()>
    <img src="image/on.gif" alt="#" id="light">
<script>
    function fun1() {
        alert("关灯 fun1");
    }
    function fun2() {
        alert("关灯 fun2")
    }

    var light = document.getElementById("light");
    light.onclick = fun2;
</script>
</body>

</html>l